/*
 *
 * Created on: 02.11.2012
 *
 * DHMessageAnalyzer.h
 * This file is part of KOBUS
 * 
 * Copyright (C) 2012 - Ivan Penkin, MIPT
 * grek.penkin@gmail.com
 *
 * KOBUS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KOBUS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with KOBUS; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 *  
 */

#ifndef DH_MESSAGEANALYZER_H_
#define DH_MESSAGEANALYZER_H_

#include <KobusCommon.h>
#include <DHConfig.h>

namespace kobus
{

namespace dhcp {

class DHMessageAnalyzer: public QObject
{
    Q_OBJECT;

  public:
    explicit
    DHMessageAnalyzer(QObject * parent = 0);

    void setRegex(const QString & /* regex */);
    void setIfaceGrpNum(qint32 num = -1);
    void setVlanGrpNum(qint32 num = -1);
    void setMacGrpNum(qint32 num = -1);
    void setIpGrpNum(qint32 num = -1);
    void setRemoteIdGrpNum(qint32 num = -1);
    void setCircuitIdGrpNum(qint32 num = -1);
    void setMessage(const QString & /* message */);

    void parse() throw (Exception);

    virtual
    HostInfo getNewHostInfo() throw (Exception) = 0;
    virtual
    void initializeByConfig() throw (Exception) = 0;

  protected:
    virtual
    void check() const throw (Exception) = 0;
    HostInfo getNewHostInfoWithoutFlags() throw (Exception);

    struct ParsingParams
    {
       ParsingParams();

       QRegExp regex;
       qint32  ifaceGrpNum;
       qint32  vlanGrpNum;
       qint32  macGrpNum;
       qint32  ipGrpNum;
       qint32  remoteIdGrpNum;
       qint32  circuitIdGrpNum;
    } parsingParms;

    struct Bufers
    {
       Bufers();
       void clearInfo();

       static const quint8 MAX_ELEMS = 6;
       enum HostInfoIndexes{IFACE = 0, MAC, IP, VLAN, REMOTE_ID, CIRCUIT_ID};

       QString message;
       QString hostInfo[MAX_ELEMS];
    } bufers;

    DHConfig config;

  private:
    Q_DISABLE_COPY(DHMessageAnalyzer);

};


}  /* namespace dhcp */
}  /* namespace kobus */

#endif /* DH_MESSAGEANALYZER_H_ */
